/**
 * ContestRule管理初始化
 */
var ContestRule = {
    id: "ContestRuleTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    width: '800px',
    height: '420px'
};

/**
 * 初始化表格的列
 */
ContestRule.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '主键ID', field: 'id', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '公司级别', field: 'companyLevel', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '公司级别代码', field: 'companyLevelCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '竞赛类型', field: 'contestType', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '竞赛类型代码', field: 'contestTypeCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '获奖类型', field: 'winType', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '获奖类型代码', field: 'winTypeCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '积分', field: 'integral', visible: true, align: 'center', valign: 'middle',sortable: true}
    ];
};

/**
 * 检查是否选中
 */
ContestRule.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ContestRule.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加ContestRule
 */
ContestRule.openAddContestRule = function () {
    var index = layer.open({
        type: 2,
        title: '添加竞赛调考积分规则',
        area: [ContestRule.width, ContestRule.height], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/contestRule/contestRule_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看ContestRule详情
 */
ContestRule.openContestRuleDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '竞赛调考积分规则详情',
            area: [ContestRule.width, ContestRule.height], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/contestRule/contestRule_update/' + ContestRule.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除ContestRule
 */
ContestRule.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/contestRule/delete", function (data) {
            Feng.success("删除成功!");
            ContestRule.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("contestRuleId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询ContestRule列表
 */
ContestRule.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    ContestRule.table.refresh({query: queryData});
};

/**
 * 打开导入ContestRule数据页面
 */
ContestRule.import = function () {
    var index = layer.open({
        type: 2,
        title: 'ContestRule',
        area: [ContestRule.width, ContestRule.height], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/contestRule/contestRule_import'
    });
    this.layerIndex = index;
};

$(function () {
    var defaultColunms = ContestRule.initColumn();
    var table = new BSTable(ContestRule.id, "/contestRule/list", defaultColunms);
    table.setPaginationType("client");
    ContestRule.table = table.init();
});
